<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WebSocket 聊天室</title>
    <link rel="stylesheet" href="css/style.css">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
</head>
<body>
    <!-- 登录页面 -->
    <div id="loginPage" class="page">
        <div class="login-container">
            <div class="login-card">
                <div class="login-header">
                    <i class="fas fa-comments"></i>
                    <h1>WebSocket 聊天室</h1>
                    <p>欢迎来到实时聊天室</p>
                </div>
                <form id="loginForm" class="login-form">
                    <div class="form-group">
                        <label for="username">用户名</label>
                        <input type="text" id="username" name="username" required placeholder="请输入用户名">
                    </div>
                    <div class="form-group">
                        <label for="password">密码</label>
                        <input type="password" id="password" name="password" required placeholder="请输入密码">
                    </div>
                    <button type="submit" class="login-btn">
                        <i class="fas fa-sign-in-alt"></i>
                        登录
                    </button>
                </form>
                <div class="login-tip">
                    <p><i class="fas fa-info-circle"></i> 提示：密码统一为 "123"</p>
                </div>
            </div>
        </div>
    </div>

    <!-- 聊天页面 -->
    <div id="chatPage" class="page hidden">
        <div class="chat-container">
            <!-- 侧边栏 -->
            <div class="sidebar">
                <div class="sidebar-header">
                    <div class="user-info">
                        <div class="avatar">
                            <i class="fas fa-user"></i>
                        </div>
                        <div class="user-details">
                            <h3 id="currentUser">用户名</h3>
                            <span class="status online">在线</span>
                        </div>
                    </div>
                    <button id="logoutBtn" class="logout-btn" title="退出登录">
                        <i class="fas fa-sign-out-alt"></i>
                    </button>
                </div>
                
                <div class="online-users">
                    <h4><i class="fas fa-users"></i> 在线用户</h4>
                    <div id="onlineUsersList" class="users-list">
                        <!-- 在线用户列表将在这里动态生成 -->
                    </div>
                </div>
            </div>

            <!-- 主聊天区域 -->
            <div class="main-chat">
                <div class="chat-header">
                    <h2><i class="fas fa-comments"></i> 聊天室</h2>
                    <div class="connection-status">
                        <span id="connectionStatus" class="status-indicator">
                            <i class="fas fa-circle"></i>
                            连接中...
                        </span>
                    </div>
                </div>

                <div class="chat-messages" id="chatMessages">
                    <div class="welcome-message">
                        <i class="fas fa-rocket"></i>
                        <p>欢迎来到聊天室！开始与朋友们聊天吧！</p>
                    </div>
                </div>

                <div class="chat-input-container">
                    <div class="input-group">
                        <select id="targetUser" class="user-select">
                            <option value="">选择聊天对象</option>
                        </select>
                        <input type="text" id="messageInput" placeholder="输入消息..." maxlength="500">
                        <button id="sendBtn" class="send-btn" disabled>
                            <i class="fas fa-paper-plane"></i>
                        </button>
                    </div>
                    <div class="input-footer">
                        <span class="char-count">0/500</span>
                        <span class="input-tip">按 Enter 发送消息</span>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 加载动画 -->
    <div id="loadingOverlay" class="loading-overlay hidden">
        <div class="loading-spinner">
            <i class="fas fa-spinner fa-spin"></i>
            <p>连接中...</p>
        </div>
    </div>

    <!-- 消息提示 -->
    <div id="messageToast" class="toast hidden">
        <i class="fas fa-info-circle"></i>
        <span id="toastMessage"></span>
    </div>

    <script src="js/chat.js"></script>
</body>
</html>
